class PublishController < ApplicationController

  before_filter :verify_session
  def index
    list
    render_action  'list'
  end

  def list
    @publishes_pages, @publishes = paginate :publishes, :per_page => 10
  end
  
  def destroy
    if Book.find(:first,:conditions =>['publish_id = ?',params[:id]])
      flash[:notice]='删除失败:存在该出版社的图书'
    else
      Publish.find(params[:id]).destroy
      flash[:notice]='删除成功'
    end
    redirect_to :action => 'list'
  end
  
  def new
    @publish = Publish.new
  end
  
  def create
    @publish = Publish.new(params[:publish])
    if @publish.save
      flash[:notice] = 'Publish was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end
  
  def edit
    @publish = Publish.find(params[:id])
  end
  
  def update
    @publish = Publish.find(params[:id])
    if @publish.update_attributes(params[:publish])
      flash[:info] = '修改成功!'
      redirect_to :action => 'list'
    else
      render :action => 'edit'
    end
  end
end
